//
//  TimeLineViewController.m
//  PSYWeiBo
//
//  Created by xiaotian on 16/3/15.
//  Copyright © 2016年 郑亚田. All rights reserved.
//

#import "TimeLineViewController.h"
#import "TimeLineDateCell.h"
#import "IdearCell.h"
#import "AlbumCell.h"
#import "DiaryBookViewController.h"
#import "AlbumDetailViewController.h"
#import "IdearDetailViewController.h"

@interface TimeLineViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation TimeLineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLab.text = @"时间轴";
    
    [self setViews];
    [self setDelegate];
}

- (void)setViews {
    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headerImgV.mas_bottom);
        make.left.right.bottom.equalTo(@0);
    }];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"IdearCell" bundle:nil] forCellReuseIdentifier:@"idearcell"];
}

- (void)setDelegate {
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

#pragma mark - tableview代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    //    cell.textLabel.text = @"test";
    
    if (indexPath.row == 0) {
        TimeLineDateCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"cellid"];
        if (!cell1) {
            cell1 = [[TimeLineDateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellid"];
        }
        
        return cell1;
    }else if (indexPath.row == 1) {
        IdearCell *cell2 = [tableView dequeueReusableCellWithIdentifier:@"idearcell" forIndexPath:indexPath];
        //    if (!cell) {
        //        cell = [[IdearCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellid"];
        //    }
        
        return cell2;
    }
    
    AlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"album"];
    if (!cell) {
        cell = [[AlbumCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"album"];
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 100;
    }if (indexPath.row == 1) {
        
    }
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.row == 0) {
        DiaryBookViewController *diaryBook = [DiaryBookViewController new];
        diaryBook.modalTransitionStyle = 2;
        [self presentViewController:diaryBook animated:YES completion:nil];
    }else if (indexPath.row == 2) {
        AlbumDetailViewController *album = [AlbumDetailViewController new];
        album.modalTransitionStyle = 2;
        [self presentViewController:album animated:YES completion:nil];
    }else {        
        IdearCell *idearcell = [tableView cellForRowAtIndexPath:indexPath];
        IdearDetailViewController *idear = [[IdearDetailViewController alloc] init];
        idear.modalTransitionStyle = 2;
//        idear.view .backgroundColor = [UIColor whiteColor];
        idear.idear = idearcell.msgLab.text;
        [self presentViewController:idear animated:YES completion:nil];
    }
}

- (CGFloat)cellHightWithString:(NSString *)str{
    //限定宽度的参数
    CGSize size = CGSizeMake(200, MAXFLOAT);
    //限定字体大小的参数
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    //计算一段文本在限定宽度,和限定字体大小的情况下占据的矩形框大小
    CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
